#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <utility>
using namespace std;

struct Catalog {
    int number;
    int kolvo;
    int post;
    float percent;

    Catalog(int n, int k, int p) : number(n), kolvo(k), post(p) {
        percent = (static_cast<float>(post) / static_cast<float>(kolvo)) * 100;
    }

    bool operator<(const Catalog& other) const {
        return percent < other.percent;
    }
};

void PrintMas(const Catalog a[], const int index[], int n) {
    cout << setw(5) << "No" << setw(15) << "Graduates" << setw(12) << "Accepted" << setw(10) << "Percent" << endl;
    for (int i = 0; i < n; i++) {
        int idx = index[i];
        cout << setw(5) << a[idx].number << setw(15) << a[idx].kolvo << setw(12) << a[idx].post << setw(10) << fixed << setprecision(2) << a[idx].percent << "%" << endl;
    }
    cout << endl;
}

int main(){
    int n = 16;
    Catalog school[16] = {
        Catalog(1, 1223, 631),
        Catalog(2, 321, 235),
        Catalog(3, 411, 186),
        Catalog(4, 2312, 902),
        Catalog(5, 123, 71),
        Catalog(6, 531, 481),
        Catalog(7, 863, 421),
        Catalog(8, 247, 134),
        Catalog(9, 512, 350),
        Catalog(10, 9421, 6491),
        Catalog(11, 23, 12),
        Catalog(12, 511, 354),
        Catalog(13, 425, 196),
        Catalog(14, 842, 381),
        Catalog(15, 953, 447),
        Catalog(16, 2467, 1894)
    };

    pair<float, int> sortedIndex[16];
    for (int i = 0; i < n; i++) {
        sortedIndex[i] = make_pair(school[i].percent, i);
    }

    sort(sortedIndex, sortedIndex + n);

    int index[16];
    for (int i = 0; i < n; i++) {
        index[i] = sortedIndex[i].second;
    }

    PrintMas(school, index, n);

    return 0;
}










№2
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <vector>
using namespace std;

struct Catalog {
    int number;
    int square;
    string faculty;
    int kolvo;
    
    Catalog(int number, int square, string faculty, int kolvo) : number(number), square(square), faculty(faculty), kolvo(kolvo) {}

};

void PrintMas(const Catalog a[], const int index[], int n) {
    cout << setw(8) << "  Номер" << setw(22) << "Площадь" << setw(22) << "Факультет" << setw(15) << "Кол-во студ" << endl;
    for (int i = 0; i < n; i++) {
        cout << setw(5) << a[i].number << setw(15) << a[i].square << setw(12) << a[i].faculty << setw(10) << fixed << setprecision(2) << a[i].kolvo << endl;
    }
    cout << endl;
}

int main(){
    int n = 16;
    std::vector<std::string> mas;
    
    Catalog hostel[16] = {
        Catalog(1, 20, "A", 3),
        Catalog(2, 25, "B", 4),
        Catalog(3, 18, "C", 3),
        Catalog(4, 16, "C", 3),
        Catalog(5, 22, "A", 4),
        Catalog(6, 20, "A", 2),
        Catalog(7, 27, "D", 4),
        Catalog(8, 14, "B", 2),
        Catalog(9, 10, "A", 2),
        Catalog(10, 21, "D", 3),
        Catalog(11, 14, "D", 3),
        Catalog(12, 27, "A", 4),
        Catalog(13, 22, "B", 3),
        Catalog(14, 19, "A", 2),
        Catalog(15, 17, "C", 3),
        Catalog(16, 20, "A", 3)
    };
    int index[16];
    
    PrintMas(hostel, index, n);
    
    std::vector<std::string> unique_faculties;
    
    for(int i = 0; i < n; i++){
        if(find(unique_faculties.begin(), unique_faculties.end(), hostel[i].faculty) == unique_faculties.end()){
            unique_faculties.push_back(hostel[i].faculty);
        }
    }
    cout << "Факультеты: ";
    int k = 0;
    for (const auto& faculty : unique_faculties){
        cout << faculty << " ";
        k++;
    }
    cout << "их " << k << "\n\n";
    
    for (const auto& faculty : unique_faculties){
        k = 0;
        for(int i = 0; i < n; i++){
            if(faculty == hostel[i].faculty){
                k++;
            }
        }
        cout << "У факультета " << faculty << " " << k << " комнат\n";
    }
    cout << endl;
    
    for (const auto& faculty : unique_faculties){
        k = 0;
        for(int i = 0; i < n; i++){
            if(faculty == hostel[i].faculty){
                k += hostel[i].kolvo;
            }
        }
        cout << "На факультете " << faculty << " " << k << " студентов\n";
    }
    cout << endl;

    int plosh = 0;
    for (const auto& faculty : unique_faculties){
        k = 0; plosh = 0;
        for(int i = 0; i < n; i++){
            if(faculty == hostel[i].faculty){
                plosh += hostel[i].square;
                k += hostel[i].kolvo;
            }
        }
        float result = static_cast<float>(plosh) / k;
        cout << "На факультете " << faculty << " средняя площадь жилья " << result << " м^2 на студента\n";
    }
    
    
    
    
    
    return 0;
}

